package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.MarketDetailBean;
import com.lwj.liwanjia.impl.MarketDetailView;
import com.lwj.liwanjia.model.MarketDetailModel;

import rx.Subscriber;

/**
 * Created by Administrator on 2017/9/26.
 */

public class MarketDetailPresenter {
    private MarketDetailView marketDetailView;
    private MarketDetailModel marketDetailModel;

    public MarketDetailPresenter(MarketDetailView marketDetailView) {
        this.marketDetailView = marketDetailView;
        marketDetailModel = new MarketDetailModel();
    }

    public void getMarketDetailData(String type,int shopInfoId, String gooddType, int sortType, String expressType) {
        if (marketDetailView != null) {
            marketDetailModel.getMarketDetailData(type, shopInfoId, gooddType, sortType, expressType, new Subscriber<MarketDetailBean>() {
                @Override
                public void onCompleted() {
                    marketDetailView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    marketDetailView.showError((Exception) e);
                    marketDetailView.hideProgress();
                }

                @Override
                public void onNext(MarketDetailBean marketDetailBean) {
                    marketDetailView.getMarketDetailData(marketDetailBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    marketDetailView.showProgress();
                }
            });
        }
    }
}
